package com.luo.wheresmytakeaway.service.impl;


import com.luo.wheresmytakeaway.mapper.UserMapper;
import com.luo.wheresmytakeaway.pojo.User;
import com.luo.wheresmytakeaway.service.UserService;
import com.luo.wheresmytakeaway.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String login(User users) {
        User user = userMapper.login(users);
        if (user != null) {
            Map<String, Object> claims = new HashMap<>();
            claims.put("userId", user.getUserId());
            claims.put("username", user.getUsername());
            claims.put("phone", user.getPhone());
            claims.put("email", user.getEmail());
            claims.put("avatar", user.getAvatar());
            return JwtUtils.generateJwt(claims);
        }else {
            return null;
        }

    }
}
